package com.ct.boot.launch.config;

import com.atomikos.icatch.jta.UserTransactionImp;
import com.atomikos.icatch.jta.UserTransactionManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.jta.JtaTransactionManager;

import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;

/**
 * @Auther: Charles chen
 * @Date: 2020/7/17 11:10
 * @Description:
 */
@Configuration
public class TransactionManagerConfig {
//    @Bean
//    public UserTransaction userTransaction() throws SystemException {
//        UserTransactionImp userTransactionImp=new UserTransactionImp();
//        userTransactionImp.setTransactionTimeout(10000);
//        return userTransactionImp;
//    }
//
//    @Bean(name = "atomikosTransactionManager",initMethod = "init",destroyMethod = "close")
//    public TransactionManager atomikosTransactionManager(){
//        UserTransactionManager userTransactionManager=new UserTransactionManager();
//        userTransactionManager.setForceShutdown(false);
//        return userTransactionManager;
//    }
//    @Bean(name = "transactionManager")
//    @DependsOn({"userTransaction","atomikosTransactionManager"})
//    public PlatformTransactionManager transactionManager() throws SystemException {
//        UserTransaction userTransaction=userTransaction();
//        TransactionManager transactionManager;
//        JtaTransactionManager manager=new JtaTransactionManager(userTransaction,atomikosTransactionManager());
//        return manager;
//    }
}
